package reflect;

import java.util.ArrayList;
import java.util.Scanner;

public class ReflectDemo2 {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException {

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要实例化的类名");
        String className = sc.nextLine();

        //1.获取要实例化的类对象
        Class cls = Class.forName(className);

        // 2.newInstance()
        Object obj = cls.newInstance();

        System.out.println(obj);

        Class cls2 = Class.forName("reflect.Person");

        Object obj2 = cls2.newInstance();
        System.out.println(obj2);
    }
}
